﻿using MediatR;
using T.Vehicleservice.API.Application.Command.ExpenseCommand;
using T.Vehicleservice.API.Application.Command.MainCommand;
using T.Vehicleservice.Repository.ImpI;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.API.Application.CommandHandlers.ExpenseCommanHandler
{
    public class ExpenseDelectCommandHandler : IRequestHandler<ExpenseDeleteCommand, int>
    {
        IExpenseRecordRepository expenseRecordRepository;

        public ExpenseDelectCommandHandler(IExpenseRecordRepository expenseRecordRepository)
        {
            this.expenseRecordRepository = expenseRecordRepository;
        }

        public async Task<int> Handle(ExpenseDeleteCommand request, CancellationToken cancellationToken)
        {
            var MainIds = request.ids;
            foreach (var item in MainIds)
            {
                var DelAll = expenseRecordRepository.GetModelAsync(item).Result;
                DelAll.IsDeleted = true;
                DelAll.DeletedBy = request.DeletedBy;
                DelAll.DeletedDate = request.DeletedDate;
                await expenseRecordRepository.UpdateAsync(DelAll);
            }
            return 1;
        }
    }
}
